<?php

use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Route;
use Dcat\Admin\Admin;

Admin::routes();

Route::group([
    'prefix' => config('admin.route.prefix'),
    'namespace' => config('admin.route.namespace'),
    'middleware' => config('admin.route.middleware'),
], function (Router $router) {

    $router->get('/', 'HomeController@index');

    $router->resource('user', 'UserController', []);
    $router->resource('role', 'RoleController', []);
    $router->resource('permission', 'PermissionController', []);

    $router->resource('category', 'CategoryController', []);
    $router->resource('topic', 'TopicController', []);
    $router->resource('reply', 'ReplyController', []);
    $router->resource('tag', 'TagController', []);

    $router->get('setting/config', 'SettingController@config')->name('setting.config');
    $router->post('setting/config', 'SettingController@configSave')->name('setting.configSave');
    $router->resource('setting', 'SettingController', []);
    $router->resource('link', 'LinkController', []);

    $router->get('api/tags', function () {

        $q = request('q');
        return \App\Models\Tag::with([])
            ->where('name', 'like', "%$q%")
            ->paginate(null, ['id', 'name as text']);
    });
});
